package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.HashMap;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-25 
 * @Version: 1.0
 */

public class LC2352相等行列对 {

    public int equalPairs(int[][] grid) {

        int len1 = grid.length;
        int len2 = grid[0].length;
        String[] m = new String[len1];
        String[] n = new String[len2];

        for (int i = 0; i < len1; i++) {
            for (int j = 0; j < len2; j++) {
                m[i] += grid[i][j] + ",";
                n[j] += grid[i][j] + ",";
            }
        }
        HashMap<String,Integer> map = new HashMap<>();

        for (int i = 0; i < len1; i++) {
            map.put(m[i],map.getOrDefault(m[i],0)+1);
        }

        int count = 0;
        for (int i = 0; i < len2; i++) {
            if (map.containsKey(n[i])){
                count += map.get(n[i]);
            }
        }


        return count;
    }

    @Test
    public void test() {
        // 测试代码

        equalPairs(new int[][]{{1,3,5,7},{10,13,16,20},{23,30,34,60}});
    }

}
